<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    <input type="text" id="txt"><span></span>
</body>
<script>

    var txt = document.querySelector("#txt");
    var span = txt.nextElementSibling;

    txt.oninput = function(){
        var str = this.value;
        // 如果输入框为空，单独提示，不验证
        if(str.length < 1){
            span.innerHTML = "不允许为空";
            return;
        }
        // 用来记录是否出现了某种字符，出现了为1
        var a = 0, b = 0, c = 0;
        for(var i=0;i<str.length;i++){
            if( str[i] >= 0 && str[i] <= 9 && str[i] !== " " ){
                // 出现数字了
                a = 1;
            }
            if( str[i] >= "a" && str[i] <= "z" || str[i] >= "A" && str[i] <= "Z" ){
                // 出现字母了
                b = 1;
            }
            if( !( str[i] >= 0 && str[i] <= 9 && str[i] !== " " || str[i] >= "a" && str[i] <= "z" || str[i] >= "A" && str[i] <= "Z" ) ){
                // 出现特殊了
                c = 1;
            }
        }
        // 根据状态和，判断当前出现了几种
        switch(a+b+c){
            case 1:
                span.innerHTML = "弱";break;
            case 2:
                span.innerHTML = "中";break;
            case 3:
                span.innerHTML = "强";break;
        }
    }

</script>
</html>